package com.atguigu.lease.common.result;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {
    private Integer code;
    private String message;
    private T data;
    private Boolean ok;

    public static <T> Result<T> build(T data, ResultCodeEnum resultCodeEnum){
        return new Result<>(resultCodeEnum.getCode(), resultCodeEnum.getMessage(), data,resultCodeEnum.getOk());
    }

    public static <T> Result<T> ok(T data){
        return Result.build(data,ResultCodeEnum.SUCCESS);
    }

    public static <T> Result<T> ok(){
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    public static <T> Result<T> error(ResultCodeEnum resultCodeEnum){
        return Result.build(null,resultCodeEnum);
    }
    public static <T> Result<T> error(){
        return Result.build(null,ResultCodeEnum.ERROR);
    }

}
